# Thu Apr  7 01:24:14 2022 edit
# 字符编码：UTF-8
# R 版本：4.2.0 alpha x64 for window 11
# cgh163email@163.com
# 个人笔记不负责任，拎了个梨🍐🍈
#.rs.restartR()

rm(list=ls());gc()
library(crosstalk)
library(leaflet)
library(leafletCN)
library(DT)
require(plotly)
#ex1 Thu Apr  7 01:24:38 2022 ------------------------------

# Wrap data frame in SharedData
sd <- SharedData$new(quakes[sample(nrow(quakes), 100),])

# Create a filter input
filter_slider("mag", "Magnitude", sd, column=~mag, step=0.1, width=250)

# Use SharedData like a dataframe with Crosstalk-enabled widgets
bscols(
  leaflet(sd) %>% addTiles() %>% addMarkers(),
  datatable(sd, extensions="Scroller", style="bootstrap", class="compact", width="100%",
            options=list(deferRender=TRUE, scrollY=300, scroller=TRUE))
)
#数据读取区bate Thu Apr  7 01:24:32 2022 ------------------------------
gz.map <-  'https://geo.datav.aliyun.com/areas_v3/bound/geojson?code=440100_full' |> sf::st_read()
dt <- readr::read_csv('广州赏花全攻略.csv')
names(dt) <- c('id','name','Month','city','add','lng','lat')
dt$inf <- tidyr::unite( dt,"inf",name,Month,add,sep = "\n🍐")[,2] |> as.matrix()
dt[1:5 ,] |> as.data.frame() |> DT::datatable(rownames = F)

dtsd <- SharedData$new(dt)
# Thu Apr  7 11:52:30 2022 ---



filter_slider("lat", "进度条标题", dtsd, column=~lat, step=0.01, width=350)
#多选器 Thu Apr  7 11:09:22 2022 ------------------------------
filter_select(dtsd,'name','木棉花','feedtype')
 filter_select("feedtype", "多选器标题", dtsd, c("木棉花",'夹竹桃'))
#batee Thu Apr  7 11:22:45 2022 ------------------------------
l <- leaflet(dtsd) |>
   amap() |>
   addCircleMarkers(lat = ~lat,lng = ~lng,popup = ~name)
l

p <- plot_ly(dtsd, x = ~lat, y = ~lng, z = ~Month) |>
  add_markers(color = ~Month)
p

bscols(
l,p
)
#end Thu Apr  7 13:35:38 2022 ------------------------------
#正式 Thu Apr  7 14:00:47 2022 ------------------------------

l <- leaflet(data = dtsd) |> amap() |>
# addTiles() |>
    addPolylines(data =gz.map,
               color = 'green'
  ) |>
  addCircleMarkers(
        lat = ~lat,lng = ~lng,
    popup = ~inf
  )
l
#dt Thu Apr  7 13:57:34 2022 ---
d <- datatable(dtsd)
d

bscols(
  l,d
)
#end Sat Apr  9 09:16:21 2022 ---


#超级pop Thu Apr  7 22:18:14 2022 ------------------------------
ls <- leaflet(data = dtsd) |> amap() |>
  # addTiles() |>
  addPolylines(data =gz.map,
               color = 'green'
  ) |>
  addCircleMarkers(
    lat = ~lat,lng = ~lng,
    popup = popupTable(dtsd$data())
  )
ls
# Thu Apr  7 22:20:39 2022 --
bscols(ls,d)
